<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            let arr = [1, 2, 3];
            let obj = {
                name: 'zs',
                age: 19,
            };
            console.log(typeof null); // object
            console.log(typeof arr); // object
            console.log(typeof obj); // object
            console.log(Object.prototype.toString.call(obj)); // [object Object]
            console.log(Object.prototype.toString.call(arr)); // [object Array]
            console.log(Object.prototype.toString.call(null)); // [object Null]

            function getType(obj) {
                let type = typeof obj;
                if (type !== 'object') {
                    // 先进行typeof判断，如果是基础数据类型，直接返回
                    return type;
                }
                // 对于typeof返回结果是object的，再进行如下的判断，正则返回结果
                return Object.prototype.toString.call(obj).slice(8, -1).toLowerCase();
            }
            console.log(getType(null));
        </script>
    </body>
</html>
